package com.notebad.ui.widgets;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.notebad.R;

/**
 * Get a new string from a dialog
 *
 */
public class TextDialog extends Dialog{

	private static final String TAG = "[TextDialog]";
	
	private EditText editText;
	private String newText = "";
	private Button button;

	public TextDialog(Context context, int theme) {
		super(context, theme);
	}

	protected TextDialog(Context context, boolean cancelable,
			OnCancelListener cancelListener) {
		super(context, cancelable, cancelListener);
	}

	public TextDialog(Context context) {
		super(context);
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		this.setContentView(R.layout.text_dialog);
		
		editText = (EditText) findViewById(R.id.textDialogField);
		button = (Button) findViewById(R.id.textDialogButton);
		
		editText.setText(newText);
		
		button.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				newText = editText.getText().toString();
				Log.e(TAG, newText);
				TextDialog.this.cancel();
			}
		});
	}
	
	public String getNewText()
	{
		Log.e(TAG, newText);
		return newText;
	}
}
